<template>
  <div class="container">
    <div>
      <span>这里用来跟机器人唠嗑</span>
      <div style="display:flex;justify-content:flex-start;align-items:center;margin-top:20px;">
        <el-input v-model="content" placeholder="请输入内容" style="width:40%"></el-input>
        <el-button type="primary" style="margin-left:20px;" @click="action">发送</el-button>
      </div>
    </div>
    <div>
      <el-table
        :data="listInfo">
        <el-table-column
          prop="reboot"
          label="智能机器人">
        </el-table-column>
        <el-table-column
          prop="user"
          label="你：">
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { sayReboot } from '@/common/common'

export default {
  data() {
    return {
      content:'',
      listInfo:[]
    }
  },
  methods:{
    action(){
      if(this.content == ''){
        this.$message.error("请输入你想说的话");
        return;
      }
      this.listInfo.push({
        user:this.content,
        reboot:''
      })
      let params = {
        content:this.content
      }
      sayReboot(params).then((res) => {
        if(res.status == 200){
          let content = JSON.parse(res.data.body)
          this.listInfo.push({
            reboot:content.content,
            user:''
          })
        }
      })
      .catch((err) => {
        console.log(err);
      })
    }
  }
}
</script>

<style>
.container {
  width: 100%;
  padding: 1%;
  margin: 0 auto;
}
</style>
